﻿using System;
using System.Buffers;
using System.Threading.Tasks;
using Beeflys;
using Beeflys.Generator.App.MyNamespace;
using System.Linq;
using System.Text;


public interface ITop
{
    public Guid guid { get; set; }
    public MyEnum MY { get; set; }
}

public class Top : ITop
{
    public Guid guid { get; set; } = Guid.NewGuid();
    public MyEnum MY { get; set; } = MyEnum.AAAAAAAAAAAAAAA;
}


public enum MyEnum
{
    AAAAAAAAAAAAAAA
}


public class Zhongzhuang
{
    public string LLL { get; } = "generated";
    public string GGG { get; set; }
}


namespace actor_test
{
    class Program
    {
        delegate T Fan<T>(byte[] bytes);


        static async Task Main(string[] args)
        {
            
            //Fan<T> fan = 

            //string name = "actor_1";

            //await World.AddActorAsync<MyClass>(name);

            //await World.DestroyActorAsync(name);

            //await World.AddActorAsync<MyClass>(name);


            Zhongzhuang zhongzhuang = new Zhongzhuang();
            zhongzhuang.GGG = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";

            //ITop _m = new Top();
            var json = System.Text.Json.JsonSerializer.Serialize<Zhongzhuang>(zhongzhuang);
            var data = System.Text.Json.JsonSerializer.Deserialize<Zhongzhuang>(json);
            System.Text.Encoding.UTF8.GetString(ReadOnlySequence<byte>.Empty);
            // System.Text.Json.JsonSerializer.
            Console.WriteLine(json);


            return;
            // long num1 = 0;
            // MyEnum item = (MyEnum) num1;
            //
            //
            var _actor = await World.AddActorAsync<MyClass, string, int>("name1", "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuu", 2001);
            var opl = _actor.Messenger<IInterface>();
            await opl.Messenger.M0();
            if (opl.ActorOpencode == ActorOpencode.SUCCEED)
            {
                
            }


            // var _actor_2 =  await World.GetActorAsync("name1");
            // Console.WriteLine(_actor_2 == null);
            // await World.DestroyActorAsync(_actor.Id.Name);
            //
            //
            // var resut = await _actor_2.CallAsync<string>(string.Empty, TimeSpan.Zero, null);


            // _actor.Messenger<>()

            // _actor.CallAsync<>()
            // _actor.Send();


            Console.ReadKey();
        }

        public static unsafe void MainTest()
        {
            delegate*<int, int, int> pointer = &Test;
            
            var result = pointer(1, 1);
            Console.WriteLine(result);
        }

        private static int Test(int num1, int num2)
        {
            Console.WriteLine($"Invoke in {nameof(Test)}, {num1}_{num2}");
            return num1 + num2;
        }



        unsafe class MyClass_1111111111
        {
            MyClass_1111111111()
            {
                pointer = &Test;
            }


            private delegate*<int, int, int> pointer;
            
            
            
            private static int Test(int num1, int num2)
            {
                Console.WriteLine($"Invoke in {nameof(Test)}, {num1}_{num2}");
                return num1 + num2;
            }
        }
    }


    unsafe class KKKKKK
    {
        
    }


    class MyClass : AActor, IAwake, IDestroy, IStart<string, int>
    {
        public Task StartAsync(string item1, int item2)
        {
            Console.WriteLine(">>>>>>>StartAsync>>" + item1+"               "+item2);

            return Task.CompletedTask;
        }


        protected override Task OnReceivedAsync(IActorContext context)
        {
            //context.Sponsor.Respond(null, ActorOpencode./*UNFOUND*/);
            
            
            return base.OnReceivedAsync(context);
        }

        public async Task OnAwakeAsync()
        {
            Logger.Info(">>>>>>>>>>>>>>MyClass.OnAwakeAsync");
            await this.AddComponentAsync<My>();
        }

        public Task OnDestroyAsync()
        {
            Logger.Info(">>>>>>>>>>>>>>MyClass.OnDestroyAsync");

            return Task.CompletedTask;
        }

        
    }

    class My : AComponent, IAwake, IDestroy
    {
        public Task OnAwakeAsync()
        {
            Logger.Info("My->Component.OnAwakeAsync");
            return Task.CompletedTask;
        }

        public Task OnDestroyAsync()
        {
            Logger.Info("My->Component.OnDestroyAsync");
            return Task.CompletedTask;
        }
    }

    sealed partial class MY_M : AMessenger, IInterface
    {
        public Task<int> M10(TestStruct str)
        {
            throw new NotImplementedException();
        }

        public void VOID(int num)
        {
            throw new NotImplementedException();
        }

        public Task M0()
        {
            throw new NotImplementedException();
        }
    }
    
    partial class MY_M : IKKKKKKKKKKKKKKK
    {
        public Task<string> KKKKKKK()
        {
            throw new NotImplementedException();
        }

        public Task<string> KKKKKKK(string p1, int p2)
        {
            throw new NotImplementedException();
        }

        Task<Top> IKKKKKKKKKKKKKKK.KKKKKKK(string p1, int p2)
        {
            throw new NotImplementedException();
        }
    }



    interface IPPPPPPPPPPPPPPPPPP
    {
        
    }


    static class Jianjiebaobao
    {
        public static string As<T>(this T item)
        {



            return string.Empty;
     
        }
    }


    class Jianjienidaye
    {

    }

    class Hanmu
    {
        public static string MMM()
        {
            return string.Empty;
        }
    }
}